//translucent //Answer：SG fresnel intensity group  
//intersect highLight depth ball and depth intersect where from depth
// urp scene check depth Texture true
//depthBall - otherObjDepth
//SG-SceneDepth Linear 【Eye】 Raw  
//ScreenPos【Raw】 xyzw means xyz is（projectScreen） position and w is depth
//  distance =  SceneDepth[eye] - screenPos.w 
//unity reverse depth near0.0 far1.0,but unity has reverse-Z, near become 1.0,far become 0.0
//rimLight
//distort

Shader "Custom/energyBall"
//最基础的透明
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,0.5) // 设置默认透明度
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _dissolveFactor ("_dissolveFactor", Range(0,1)) = 0.5
    }

    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        // 基本渲染
        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows alpha:fade
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG

        // 毛发渲染shell
        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows vertex:vert alpha:blend
        #pragma target 3.0

        sampler2D _MainTex;
        half _dissolveFactor;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        half _FurLength;

        void vert(inout appdata_full v)
        {
            v.vertex.xyz += v.normal * _FurLength; // Add fur to the vertex position
        }

        void surf (Input IN, inout SurfaceOutputStandard o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;

            fixed4 simpleNoise = noise();
            float dissolveFactor = 0.38;
            float color =   simpleNoise + 0.01;
            step(0.1,color);
            float thresold2 = step(0.1,dissolveFactor + 0.01);
            fixed4 colorEdgeBase = fixed4(1.0,0.0,0.0,0.0);
            fixed4 colorEdge = thresold2 * colorEdgeBase;
    //HDR color changedChanged To 4，and add postprocessing
            float alphaClip = c.a;
            fixed finalColor = colorEdge + c;

            if(alphaClip > dissolveFactor){
                clip();
            }


            
        }
        ENDCG
    }

    FallBack "Diffuse"
}